package com.example.administrator.libraryclub.fragment;

import android.app.Fragment;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.libraryclub.R;
import com.fmblzf.library.text.TextViewBorderColor;
import com.fmblzf.library.view.TriangleView;

/**
 * Created by Administrator on 2015/10/21.
 */
public class FirstFragment  extends Fragment implements View.OnClickListener {

    TextViewBorderColor tvPaiMai ;
    TextViewBorderColor tvJInJia ;
    TextViewBorderColor tvMaiMain ;
    TextViewBorderColor tvRenGou ;
    TriangleView lineView;
    private TextViewBorderColor curTextView;
    private int curLocation = 0;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.first_fragment_layout,null,true);
        initViews(view);
        return view;
    }

    private void initViews(View view) {

        lineView = (TriangleView) view.findViewById(R.id.tv_line);

        tvPaiMai = (TextViewBorderColor) view.findViewById(R.id.tv_paimai);
        tvPaiMai.setOnClickListener(this);
        tvJInJia = (TextViewBorderColor) view.findViewById(R.id.tv_jinjia);
        tvJInJia.setOnClickListener(this);
        tvMaiMain = (TextViewBorderColor) view.findViewById(R.id.tv_maimai);
        tvMaiMain.setOnClickListener(this);
        tvRenGou = (TextViewBorderColor) view.findViewById(R.id.tv_rengou);
        tvRenGou.setOnClickListener(this);
        curTextView = tvPaiMai;
    }

    @Override
    public void onClick(View view) {
        if(curTextView == view)
            return;
        if (view instanceof TextViewBorderColor) {
            TextViewBorderColor textView = (TextViewBorderColor) view;
            textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
            textView.setIsFouce(true);
            curTextView.setIsFouce(false);
            curTextView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
            curTextView = textView;
        }
        switch (view.getId()){
            case R.id.tv_paimai:
//                tvPaiMai.setTextColor(Color.RED);
//                curTextView.setTextColor(Color.BLACK);
//                curTextView = tvPaiMai;
                curLocation = 0;
                break;
            case R.id.tv_jinjia:
//                tvJInJia.setTextColor(Color.RED);
//                curTextView.setTextColor(Color.BLACK);
//                curTextView = tvJInJia;
                curLocation = 1;
                break;
            case R.id.tv_maimai:
//                tvMaiMain.setTextColor(Color.RED);
//                curTextView.setTextColor(Color.BLACK);
//                curTextView = tvMaiMain;
                curLocation = 2;
                break;
            case R.id.tv_rengou:
//                tvRenGou.setTextColor(Color.RED);
//                curTextView.setTextColor(Color.BLACK);
//                curTextView = tvRenGou;
                curLocation = 3;
                break;
            default:
                break;

        }

        lineView.setCurStatus(curLocation);
    }

    @Override
    public void onResume() {
        super.onResume();
        lineView.setCurStatus(curLocation);
        curTextView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
        curTextView.setIsFouce(true);
    }
}
